/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.NamedEntry.Visitor;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.fb.FreeBusyProvider;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PushFreeBusy
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  40 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  41 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  43 */     Element domainElem = request.getOptionalElement("domain");
/*  44 */     if (domainElem == null) {
/*  45 */       Iterator<Element> accounts = request.elementIterator("account");
/*  46 */       while (accounts.hasNext()) {
/*  47 */         String accountId = ((Element)accounts.next()).getAttribute("id", null);
/*  48 */         if (accountId != null)
/*     */         {
/*  50 */           Account acct = prov.get(Key.AccountBy.id, accountId, zsc.getAuthToken());
/*  51 */           if (acct == null) {
/*  52 */             ZimbraLog.misc.warn("invalid accountId: " + accountId);
/*     */ 
/*     */           }
/*  55 */           else if (!Provisioning.onLocalServer(acct)) {
/*  56 */             ZimbraLog.misc.warn("account is not on this server: " + accountId);
/*     */           }
/*     */           else {
/*  59 */             checkAdminLoginAsRight(zsc, prov, acct);
/*  60 */             FreeBusyProvider.mailboxChanged(accountId);
/*     */           }
/*     */         }
/*  63 */       } } else { String[] domains = domainElem.getAttribute("name").split(",");
/*  64 */       Server s = prov.getLocalServer();
/*  65 */       NamedEntry.Visitor visitor = new PushFreeBusyVisitor(zsc, prov, this);
/*  66 */       for (String domain : domains) {
/*  67 */         Domain d = prov.get(Key.DomainBy.name, domain);
/*  68 */         prov.getAllAccounts(d, s, visitor);
/*     */       }
/*     */     }
/*     */     
/*  72 */     Element response = zsc.createElement(AdminConstants.PUSH_FREE_BUSY_RESPONSE);
/*  73 */     return response;
/*     */   }
/*     */   
/*     */   private static class PushFreeBusyVisitor implements NamedEntry.Visitor
/*     */   {
/*     */     ZimbraSoapContext mZsc;
/*     */     Provisioning mProv;
/*     */     AdminDocumentHandler mHandler;
/*     */     
/*     */     PushFreeBusyVisitor(ZimbraSoapContext zsc, Provisioning prov, AdminDocumentHandler handler) {
/*  83 */       this.mZsc = zsc;
/*  84 */       this.mProv = prov;
/*  85 */       this.mHandler = handler;
/*     */     }
/*     */     
/*     */     public void visit(NamedEntry entry) throws ServiceException {
/*  89 */       if (((entry instanceof Account)) && (Provisioning.onLocalServer((Account)entry))) {
/*  90 */         Account acct = (Account)entry;
/*  91 */         String[] fps = acct.getForeignPrincipal();
/*  92 */         if ((fps != null) && (fps.length > 0)) {
/*  93 */           for (String fp : fps) {
/*  94 */             if (fp.startsWith("ad:")) {
/*  95 */               int idx = fp.indexOf(':');
/*  96 */               if (idx != -1) {
/*  97 */                 this.mHandler.checkAdminLoginAsRight(this.mZsc, this.mProv, acct);
/*  98 */                 FreeBusyProvider.mailboxChanged(acct.getId());
/*  99 */                 break;
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 110 */     relatedRights.add(Rights.Admin.R_adminLoginAs);
/* 111 */     relatedRights.add(Rights.Admin.R_adminLoginCalendarResourceAs);
/* 112 */     notes.add("If the target is an account, need the adminLoginAs right; If the target is a calendar resource, need the R_adminLoginCalendarResourceAs right.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/PushFreeBusy.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */